import Mock from "mockjs";
import { Local } from "../utils";
class payEntity {
  fieldsSession = Local('payEntity-fields', Mock.mock([
    {
      pay_name: "支付宝支付",
      pay_type: "alipay",
      pay_url: '/systemConfiguration/paymentSet/alipayPaymentPage',
      desc: '@cword(20)',
      "is_use|0-1": 0,
      icon: Mock.Random.image('200x200', '#FF6600')
    },
    {
      pay_name: "银联支付",
      pay_type: "unionpay",
      pay_url: '/systemConfiguration/paymentSet/unionPaymentPage',
      desc: '@cword(20)',
      "is_use|0-1": 0,
      icon: Mock.Random.image('200x200', '#FF6600')
    },
    {
      pay_name: "微信支付",
      pay_type: "wxpay",
      pay_url: '/systemConfiguration/paymentSet/wxPaymentPage',
      desc: '@cword(20)',
      "is_use|0-1": 0,
      icon: Mock.Random.image('200x200', '#FF6600'),
      mch_id: "wx" + "@word(12)",
      transfer_type: 'v2',
      pay_signkey: '',
      v3_pay_signkey: '',
      apiclient_cert: '',
      apiclient_key: '',
      pay_status: 0,
      refund_status: 0,
      transfer_status: 0,
    }
  ]))
  get fields() {
    return this.fieldsSession.get();
  }
  set fields(obj: any) {
    this.fieldsSession.set(obj)
  }
  findAll() {
    return this.fields;
  }
  update(pay_type: string, rows: any) {
    let fields = this.fields || [];
    let idx = fields.findIndex((x:any) => x.pay_type === pay_type);
    Object.entries(rows).forEach((item:any) => {
      fields[idx][item[0]] = item[1];
    })
    this.fields = fields;
  }
}

export default payEntity;